package cn.itsource.direct;

import cn.itsource.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

//发送者
public class Send {
    //交换机的名字
    public static  final String EXCHANGE_NAME_DIRECT_1107 = "exchange_name_direct_1107";

    public static void main(String[] args) throws Exception {

        try(
                //1.创建连接对象
                Connection connection = ConnectionUtil.getConnection();
                //2.创建通道
                Channel channel = connection.createChannel();
        ) {
            //3.声明一个交换机 名字加类型
            channel.exchangeDeclare(EXCHANGE_NAME_DIRECT_1107, BuiltinExchangeType.DIRECT);
            //4模拟一个消息内容
            String message = "FANOUT哈哈哈哈哈哈";
            //5.使用默认的交换机 发送消息给指定的队列
            channel.basicPublish(
                    EXCHANGE_NAME_DIRECT_1107,  //定义的交换机
                    "R1",   //空的 因为没有声明队列
                    null,   //额外参数，这里不需要
                    message.getBytes()  //消息内容
            );
            System.out.println("消息发送完毕"+message);
        }
    }
}

